package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingPlanVo;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 护理项目Controller类
 */
@RestController
@RequestMapping("/nursing_project")
@Api(tags = "护理项目管理")
public class NursingProjectController extends BaseController{

    @Autowired
    private NursingProjectService nursingProjectService;

    @GetMapping
    @ApiOperation("分页查询护理项目列表")
    public ResponseResult<PageResponse<NursingProjectVo>> getByPage(
            @ApiParam(value = "护理项目名称")  String name,
            @ApiParam(value = "状态：0-禁用，1-启用") Integer status,
            @ApiParam(value = "当前页码")
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @ApiParam(value = "每页显示数量")
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {
        PageResponse<NursingProjectVo> nursingProjectPageInfo = nursingProjectService.getByPage(name, status, pageNum, pageSize);
        return success(nursingProjectPageInfo);
    }

    @PostMapping
    @ApiOperation("新增护理项目")
    public ResponseResult save(
            @ApiParam(value = "添加护理项目信息") @RequestBody NursingProjectDto dto){
            Boolean resout = nursingProjectService.insert(dto);
        return success();
    }

    @GetMapping("/{id}")
    @ApiOperation("回显项目")
    public ResponseResult selectById(
            @ApiParam(value = "护理工程id")
            @PathVariable Long id){
        NursingProjectVo vo = nursingProjectService.selectById(id);
        return success(vo);
    }

    @PutMapping()
    @ApiOperation("修改项目")
    public ResponseResult update(
            @ApiParam(value = "护理工程实例")
            @RequestBody NursingProjectDto dto){
        Boolean resout=nursingProjectService.update(dto);
        return success(resout);
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除护理项目")
    public ResponseResult delete(
            @ApiParam(value = "护理工程id")
            @PathVariable Long id){
        Boolean resout=nursingProjectService.delete(id);
        return success(resout);
    }


    @PutMapping("/{id}/status/{status}")
    @ApiOperation("修改状态")
    public ResponseResult changeStatus(
            @ApiParam(value = "护理工程id")
            @PathVariable Long id,
            @PathVariable Integer status){
        Boolean resout=nursingProjectService.changeStatus(id,status);
        return success(resout);
    }

    @GetMapping("/all")
    @ApiOperation("返回所有")
    public ResponseResult all(){
        List<NursingProjectVo> nursingPlanVos= nursingProjectService.list();
        return success(nursingPlanVos);
    }

}